<template>
  <div class="wrap">
    <div class="d-flex align-items-center">
      <!--      <label class="el-form-item__label">{{$t('message.MBDMirrorAndCopy.mirrorPlane')}}：</label>-->
      <query-list
          :tipMsg="$t('message.MBDMirrorAndCopy.mirrorPlane')"
          v-model="params.mirrorPlane"
          @removeItem="removeSelect"
          :active="params.queryListActiveMap.mirrorPlane"
          @switchQuery="switchQuery('mirrorPlane')"/>
    </div>
    <div class="d-flex align-items-center">
      <!--      <label class="el-form-item__label">{{$t('message.MBDMirrorAndCopy.Instance')}}：</label>-->
      <query-list
          :tipMsg="$t('message.MBDMirrorAndCopy.Instance')"
          v-model="params.selInstance"
          @removeItem="removeSelect"
          :active="params.queryListActiveMap.selInstance"
          @switchQuery="switchQuery('selInstance')"/>
    </div>
    <div class="btn">
      <el-button
          type="primary"
          size="small"
          :disabled="!isConfirm"
          @click="confirm">
        {{ $t('message.MBDMirrorAndCopy.confirm') }}
      </el-button>
      <el-button
          size="small"
          @click="cancel">
        {{ $t('message.MBDMirrorAndCopy.cancel') }}
      </el-button>
    </div>
  </div>
</template>

<script>
import {ElementType, EntityType} from "../../modeling/TypeDefine"
import {ELEMENT} from "../../../nodeApp/static/lib/vuejs/element-ui";
import {mbdCommand} from "../../Command/MbdCommand";
import {element} from "three/nodes";
import DialogMixin from "./DialogMixin";

export default {
  mixins: [DialogMixin],
  data() {
    return {
      params: {
        mirrorPlane: [],
        selInstance: [],
        mirrorFileNames: [],
        enableLink: true,
        isCreate: false,
        reverseDirection: true,
        lockedProperty: {
          selInstance: false
        },
        queryListActiveMap: {
          mirrorPlane: 1,
          selInstance: 0
        },
      }
    }
  },

  mounted() {
    mbdCommand.init(400, 300, 150, () => {
      this.handlePick();


      // 1.基准面选择处理
      /*   if (this.params.queryListActiveMap.mirrorPlane === 1) {
           commonPickCommand.handlePickElement((elements) => {
             if (elements.length == 0) return;
             // 清空上次的实例选择
             this.params.mirrorPlane.splice(0);
             this.filterFace(elements);
             // 加入本次的实例选择
             elements.forEach(ele => {
               if (ele.id > 0) {
                 this.params.mirrorPlane.push(ele);
               }
             })
           });
         }*/

      // 2实例选择处理
      /*      mbdCommand.handlePickInstance((instances) => {

              if (this.params.queryListActiveMap.mirrorPlane === 1) {
                instances.forEach(ins => {
                  //if (ins.type === ElementType.DATUMPLANE || ins.type === ElementType.FACE) {
                  if (ins.type === 10) {
                    this.params.mirrorPlane.push(ele);
                  }
                })
              }

              if(this.params.queryListActiveMap.selInstance === 1){
                if (instances.length == 0) return;
                //this.params.selInstance.splice(0);
                instances.forEach(ins => {
                  if (ins.id > 0) {
                    this.params.selInstance.push(ins);
                  }
                })
              }
            });*/

    });
  },

  methods: {
    handlePick() {
      mbdCommand.handlePickElement((instances) => {
        if (instances.length == 0) return;
        //面选择
        if (this.params.queryListActiveMap.mirrorPlane === 1) {
          this.params.mirrorPlane.splice(0);

          let tempIns = instances[0];
          let ins = {
            id: 0,
            name: "",
            type: 0
          };

          if (tempIns?.type === 10) {
            ins.id = tempIns?.id,
                ins.name = tempIns?.name,
                ins.type = tempIns?.type
          } else if (tempIns?.faceId > 0) {
            ins.id = tempIns?.faceId;
            ins.name = tempIns?.faceName;
            ins.type = tempIns?.faceType;
          } else {

          }

          if (ins.id > 0) {
            this.params.mirrorPlane.push(ins);
          }
        } else if (this.params.queryListActiveMap.selInstance === 1) {
          // 实例选择
          this.params.selInstance.splice(0);
          let tempIns = instances[0];
          let ins = {
            id: tempIns?.id,
            name: tempIns?.name,
            type: tempIns?.type
          };
          this.params.selInstance.push(ins);
        }
      })
    },

    switchQuery(name) {
      for (const key in this.params.queryListActiveMap) {
        this.params.queryListActiveMap[key] = key === name ? 1 : 0;
      }
    },

    confirm() {
      let createParams = {
        plane: this.params.mirrorPlane[0],
        instance: this.params.selInstance,
      };
      mbdCommand.mbdCreateMirror(createParams);
    },

    cancel() {
      mbdCommand.closeActiveCmd();
    },

    changePluginContainerHeight() {
      mbdCommand.changePluginContainerHeight({minWidth: this.$el.clientWidth, maxHeight: this.$el.clientHeight})
    }
  },

  watch: {
    "params.mirrorPlane": function () {
    },
  },

  computed: {
    isConfirm() {
      return 1;
    }
  }
}
</script>

<style scoped>
.wrap {
  font-size: 12px;
}

label {
  color: var(--text-color1);
}

</style>